{extend name="../public/header" /}
{block name="body"}
<body>
{include file="../public/top" uname="$roleInfo.uname" lv="$roleInfo.ulv" ls="$roleInfo.uyxb" jp="$roleInfo.uczb" /}
<div class="subject main">
    <div class="layui-row">
        <div class="content">
            <div class="current">
                <span class="position">{$roleInfo.map.mname}</span>
                <span class="state">{if $roleInfo.map.ispvp==0}[安全区]{else/}[PVP]{/if}</span>
                <span class="info ajax-goto" data-url="{:url('index')}">返回</span>
            </div>
            <div class="npc">
                <div class="layui-card">
                    <div class="layui-card-header">[Lv:{$info.nlv}] {$info.nname} <span class="nickname">{if $info.nickname!=''}<{$info.nickname}>{/if}</span></div>
                    <div class="layui-card-body">{$info.ninfo|default=''}</div>
                </div>
                <div class="layui-panel">
                    <div style="padding:10px;">
                        <a class="ajax-opt" data-url="{:url('home/treat')}">[你会很快好起来]</a>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
{/block}
{block name="script"}
<script>
    layui.use(['jquery', 'form', 'layajax', 'upload', 'flow', 'element'], function () {
        var $ = layui.jquery
            , layajax = layui.layajax
            , upload = layui.upload
            , element = layui.element
            , flow = layui.flow
            , form = layui.form;

        $('.ajax-opt').on('click', function () {
            var obj = $(this);
            var url = obj.data('url');

            console.log('url',url);

            $.post(url, {}, function (res) {
                if (res.code == undefined) {
                    console.log('res为json字符串', res);
                    res = JSON.parse(res);
                } else {
                    console.log('res为json对象', res);
                }
                if (res.code == 1) {
                    layer.msg(res.msg,{icon:1,time:2000}, function(index){
                        if(res.data.url!='' && res.data.url!=undefined){
                            window.location.href = res.data.url;
                        }else{
                            location.reload();
                        }
                    });
                } else {
                    layer.msg(res.msg);
                }
            });
        });

        form.render();
    });
</script>
{/block}